package com.qc.serviceedu.controller;


import com.qc.commonutils.result.R;
import com.qc.serviceedu.client.VodClient;
import com.qc.serviceedu.entity.EduChapter;
import com.qc.serviceedu.entity.chapter.ChapterVo;
import com.qc.serviceedu.service.EduChapterService;
import com.qc.serviceedu.service.EduVideoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author AltmanQc
 * @since 2020-12-25
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;

    @Autowired
    private VodClient vodClient;

    @ApiOperation("根据id获取章节信息")
    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable  String courseId){
        List<ChapterVo> list = chapterService.getChapterVideo(courseId);
        return R.ok().data("items",list);
    }

    //添加
    @ApiOperation("添加章节信息")
    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter chapter){
        chapterService.save(chapter);
        return R.ok();
    }

    //根据章节id查询
    @ApiOperation("添加章节信息")
    @GetMapping("getChapterInfo/{chapterId}")
    public R getChapterInfo(@PathVariable String chapterId){
        EduChapter eduChapter = chapterService.getById(chapterId);
        return R.ok().data("chapter",eduChapter);
    }

    //修改
    @ApiOperation("修改章节信息")
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter chapter){
        chapterService.updateById(chapter);
        return R.ok();
    }

    //删除
    @ApiOperation("删除章节信息")
    @DeleteMapping("{chapterId}")
    public R deleteChapter(@PathVariable String chapterId){
        chapterService.deleteChapter(chapterId);
        return R.ok();
    }

}

